package com.tedu.ivos.dictoption.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tedu.ivos.base.response.JsonResult;
import com.tedu.ivos.dictoption.pojo.dto.DictOptionParam;
import com.tedu.ivos.dictoption.pojo.dto.DictOptionQuery;
import com.tedu.ivos.dictoption.pojo.vo.DictOptionVO;
import com.tedu.ivos.dictoption.service.DictOptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "字典模块")
@RequestMapping("/v1/dictOption/")
public class DictOptionController {

    @Autowired
    private DictOptionService dictOptionService;

    @ApiOperation(value = "查询字典项信息")
    @ApiOperationSupport(order = 10)
    @PostMapping("select")
    public JsonResult selectDictOption(DictOptionQuery dictOptionQuery) {
        log.debug("查询字典项信息，参数：{}", dictOptionQuery);
        List<DictOptionVO> list = dictOptionService.selectDictOption(dictOptionQuery);

        return JsonResult.ok(list);
    }

    @ApiOperation(value = "保存字典项")
    @ApiOperationSupport(order = 20)
    @PostMapping("save")
    public JsonResult saveDictOption(DictOptionParam dictOptionParam) {
        log.debug("保存字典项，参数：{}", dictOptionParam);
        dictOptionService.saveDictOption(dictOptionParam);

        return JsonResult.ok();
    }

    @ApiOperation(value = "删除字典项")
    @ApiOperationSupport(order = 30)
    @PostMapping("delete/{id}")
    public JsonResult deleteDictOption(@PathVariable Long id) {
        log.debug("删除字典项，参数：{}", id);
        dictOptionService.deleteDictOption(id);

        return JsonResult.ok();
    }

    @ApiOperation(value = "更新字典项")
    @ApiOperationSupport(order = 40)
    @PostMapping("selectById/{id}")
    public JsonResult selectById(@PathVariable Long id) {
        log.debug("查询字典项，参数：{}", id);
        DictOptionVO dictOptionVO = dictOptionService.selectById(id);

        return JsonResult.ok(dictOptionVO);
    }

    @ApiOperation(value = "根据DictCode字典查DictOption字典项")
    @ApiOperationSupport(order = 50)
    @GetMapping("select/{code}")
    public JsonResult selectDictOptionByDictCode(@PathVariable String code) {
        log.debug("根据字典Code查字典项，参数：{}", code);
        List<DictOptionVO> list = dictOptionService.selectDictOptionByDictCode(code);

        return JsonResult.ok(list);
    }
}